package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.ContentDao;
import com.pojo.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContentService extends ServiceImpl<ContentDao, Content> {

    @Autowired
    private ContentDao contentDao;

    /**
     * 分页查询图片+文本内容
     * @param mId 所属模块Id
     * @return
     */
    public IPage<Content> selectContentByImgText (Integer page, Integer limit, String mId) {
        Page p = new Page(page, limit);
        QueryWrapper query = new QueryWrapper();
        query.eq("mId", mId);

        IPage iPage = contentDao.selectPage(p, query);
        return iPage;
    }

    /**
     * 根据模块ID获取模块内容
     * @param mId 所属模块Id
     * @return
     */
    public List<Content> getContentByMId (String mId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("mId", mId);
        return contentDao.selectList(query);
    }

    /**
     * 根据模块ID获取图片路径
     * @param mId 所属模块Id
     * @return
     */
    public List<String> getImgsSrcByMId (String mId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("mId", mId);
        return contentDao.getImgsSrcByMId(mId);
    }


    /**
     * 根据模块ID删除模块内容
     * @param mId 所属模块Id
     * @return
     */
    public int deleteContents(String mId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("mId", mId);
        return contentDao.delete(query);
    }
}
